<template>
	<view>
		<view class="recommend">
			<price-commodity class="item" type="1" v-for="(item,index) in orderList" :key="index" :id="item.unid"
				:src="item.mainImg" :price="item.score" :change="item.sales" :describe="item.goods_name"
				@event="handelPriceCommodity">
			</price-commodity>
		</view>
	</view>
</template>

<script>
	import priceCommodity from '@/components/commodityShow/price-commodity.vue';
	export default {
		components: {
			priceCommodity
		},
		data() {
			return {
				orderList: [],
				page: 1,
				reload: true,
				isPage: false,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '—— 没有更多了 ——',
					contentnot: "没数据"
				}
			}
		},
		onPullDownRefresh() {
			this.publicFunc();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getOrder();
			}, 500);
		},
		onShow() {
			this.publicFunc();
		},
		methods: {
			// 获取订单列表
			getOrder() {
				if (this.page == 1) {
					uni.showLoading({
						title: '加载中',
						mask: true
					});
				}
				var data = {
					page: this.page,
					activities: 4
				}
				this.$shopApi.apiPost('font/goods/infos', data).then(res => {
					if (res.data.code == 200 && res.data.data.list && res.data.data.list.length > 0) {
						var list = res.data.data.list;
						list.forEach(item => {
							item['mainImg'] = this.util.getMainImage(item.images);
						})
						this.total = res.data.data.total;
						this.orderList = this.reload ? list : this.orderList.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.orderList = [];
							this.isPage = true;
						} else {
							this.status = 'noMore';
						}
					}
					uni.hideLoading();
				})
			},
			// 前往详情页
			handelPriceCommodity(e) {
				this.$interface.routeLink({
					route: 'pointDetail',
					data: {id: e}
				})
			},
			// 公用方法
			publicFunc() {
				this.page = 1;
				this.reload = true;
				this.isPage = false;
				this.orderList = [];
				this.getOrder();
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: 100upx;
	}

	.recommend {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		width: calc(100% - 60upx);
		margin: auto;

		.item {
			width: calc(50% - 9upx);
		}
	}
</style>
